<template>
  <div>
    <el-input v-model="searchText" placeholder="搜索" />
    <el-tree
      :expand-on-click-node="false"
      ref="tree"
      :data="dataTree"
      :props="defaultProps"
      default-expand-all
      :filter-node-method="filterNode"
      class="filter-tree"
      @node-click="node"
    />
  </div>
</template>
<script>
import { GetDepTree } from '@/api/system';

export default {
  props: {},
  data() {
    return {
      searchText: '',
      dataTree: [],
      defaultProps: {
        children: 'children',
        label: 'title'
      }
    }
  },
  watch: {
    searchText(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    this.getTreeData();
  },
  methods: {
    getTreeData() {
      GetDepTree().then(res => {
        if (res.code === 200) {
          this.dataTree = [{
            id: 0,
            title: '淮南统战部',
            children: res.data
          }]
        }
      })
    },
    filterNode(value, data) {
      if (!value) return true;
      console.log('data.title.indexOf(value) !== -1', data.title.indexOf(value) !== -1)
      return data.title.indexOf(value) !== -1;
    },
    node(data) {
      console.log(1111, data);
      this.$emit('nodeClick', data);
    }
  }
}
</script>
<style lang="scss" scoped>
  ::v-deep .el-input__inner{
    width: 90%;
    margin: 0 auto;
  }
  .filter-tree{
    margin-top: 10px;
      ::v-deep .el-tree-node{
        width: 90%;
        margin: 0 auto;
      }
      ::v-deep .el-tree-node__content{
        height: 40px;
      }
    }
</style>
